Ext.onReady(function(){
	User_DeskTop.initPage();
});

var User_DeskTop={
		initPage: function(){
			Ext.create('Ext.container.Viewport', {
			    layout: 'border',
			    frame:false,
			    border:false,
			    items: [{
			    	id: 'mainPanel',
			        region: 'center',
			        layout: 'fit',
			        items:[User_DeskTop.createUserGrid()]
			    }]
			});
		},
		createUserGrid: function(){
			var usergrid = Ext.create('Ext.com.bkfm.datagrid', {
				id: "user",
				objPath : "ROOT/XTGLPT/JCSJGL/YHXX/BLK_BASE_USERS",
				border: true,
				orderby : ' ORDER BY USER_NO ASC',
				afterFormShow: function(grid,formTabPanel){
					if(formTabPanel.getActiveTab(0).getFormState() == Constants.RECORD_CHANGED){
						var user_pwd_field = formTabPanel.getActiveTab(0).findById("user_pwd");
						user_pwd_field.old_value = user_pwd_field.getValue();
					}
				},
				beforeFormSave: function(grid,formTabPanel,win){
					if(formTabPanel.getActiveTab(0).getFormState() == Constants.RECORD_CHANGED){
						//密码有变动，重新设置密码
						var user_pwd_field = formTabPanel.getActiveTab(0).findById("user_pwd");
						if(user_pwd_field.old_value != user_pwd_field.getValue()){
							user_pwd_field.setValue(Utils.md5(user_pwd_field.getValue()));
						}
					}else{
						var user_pwd_field = formTabPanel.getActiveTab(0).findById("user_pwd");
						//新增直接设置密码
						user_pwd_field.setValue(Utils.md5(user_pwd_field.getValue()));
					}
				}
			});
			
			return usergrid;
		}
}